function [lpost,llik,filtmv,sysm] = logpost(para,data,msel,nparticle,approx)
% [LPOST,LLIK,FILTMV,SYSM]= LOGPOST(DATA,SYSM,NPARTICLE)
% computes log of the posterior density
%
% INPUT
%	PARA	  : parameters, (npara by 1)
%   DATA      : data,  (nobs by ndata)
%   NPARTICLE : number of particles used for particle filter
%				run Kalman filter if omitted
%   APPROX    : approximation order, 1 or 2
%
% OUTPUT
%	LPOST	: log of posterior density, (1 by 1)
%   LLIK	: log likelihood, (1 by 1)
%   FILTMV	  : filtered means and variances
%             .s0       : conditional mean z(t|t), t=0,...,T, ns by T+1
%*            .s1       : mean of forecast z(t+1|t), t=0,...,T-1, ns by T
%*            .ltrvecP0 : conditional variances of states,
%*                        lower triangular part of P(t|t), ns*(ns+1)/2 by T+1
%*            .ltrvecP1 : variances of forecasts of states,
%*                        lower triangular part of P(t+1|t), ns*(ns+1)/2 by T
%   SYSM	: system matrices

% Sungbae An
% created: 06/09/2004
% updated: 07/21/2005 


%------------------------------------------------
% posterior specification 
%	0 : prior*likelihood
%	1 :	likelihood only
%	2 : prior only
%------------------------------------------------
post_spec = 0;


%------------------------------------------------
% prior
%------------------------------------------------
if post_spec==1
	lprior = 0;
else
	% evaluate log prior density
	lprior = logprior(para);
end

%------------------------------------------------
% likelihood
%------------------------------------------------
if post_spec==2
	llik=0;filtmv=0;sysm=0;
else
	% evaluate log likelihood
	if nargin==3		% Kalman filter
		[llik,filtmv,sysm] = loglik(para,data,msel);
	elseif nargin==4	% particle filter
		[llik,filtmv,sysm] = loglik(para,data,msel,nparticle);
	elseif nargin==5	% particle filter
		[llik,filtmv,sysm] = loglik(para,data,msel,nparticle,approx);
	else
		error('check number of input arguments.' );
	end
end

%------------------------------------------------
% log posterior density
%------------------------------------------------
lpost  = llik + lprior;
